<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh" xmlns="http://www.w3.org/1999/xhtml">
<!-- 古韵超市 · 主页 -->
<?php
session_start();
?>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>古韵超市 · 主页</title>
    <link rel="stylesheet" href="bootstrap-5.3.3-dist/bootstrap.min.css">
    <script src="bootstrap-5.3.3-dist/bootstrap.min.js"></script>
    <link rel="stylesheet" href="index.css">
</head>

<body>
    <!-- 导航 -->
    <div class="navbar fixed-top">
        <nav class="navbar navbar-expand-lg navbar-light bg-light" id="navbar">
            <div class="container-fluid">
                <div class="logo_div">
                    <img src="LOGO.png">
                </div>
                <a class="navbar-brand" href="index.html">古韵超市网上购物系统</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                    data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link active" aria-current="page" href="#navbar">首页</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="userfiles/u_all_goods.php">所有商品</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="userfiles/u_mycart.php">我的购物车</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="userfiles/u_show_order.php">我的订单</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="userfiles/u_history_order.php">历史订单</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="userfiles/u_personal_info.php">我的信息</a>
                        </li>
                    </ul>
                    <div class="infobox">
                        <?php
                        if (!isset($_SESSION['USERINFOS'])) {
                            echo "<a href='userfiles/login_reg.html'>登录注册</a>";
                        } else {
                            echo "当前登录：" . $_SESSION['USERINFOS']['uname'] . " | <a href='userfiles/php/logout.php'>退出登录</a>";
                        }
                        ?>

                    </div>
                </div>
            </div>
        </nav>
    </div>
    <!-- 轮播图 -->
    <div id="carouselExampleIndicators" class="carousel slide lunbo" data-bs-ride="carousel">
        <ol class="carousel-indicators">
            <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active"></li>
            <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1"></li>
            <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2"></li>
            <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="3"></li>
        </ol>
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="img/banner_1.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item">
                <img src="img/banner_2.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item">
                <img src="img/banner_3.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item">
                <img src="img/banner_4.jpg" class="d-block w-100">
            </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </a>
    </div>
    <main>
        <?php
        $conn = mysqli_connect("localhost", "root", "root", "pss");
        if (!$conn) {
            die("<script>alert('数据库连接失败！');history.go(-1);</script>");
        }

        mysqli_query($conn, "SET NAMES UTF8");
        ?>
        <div class="container">
            <div class="types_title">
                <span class="types_title_img">
                    <img src="img/蔬菜.svg">
                </span>
                <span class="types_title_text">有机蔬菜</span>
                <span class="types_title_more"><a href="">更多></a></span>
            </div>
            <div class="types_content">
                <?php
                //查询蔬菜类别售卖数量前4商品
                $sql_grain = "SELECT * FROM tb_goods_info WHERE g_type = '蔬菜' AND g_is_sell = 1 ORDER BY g_sell_num DESC LIMIT 4";
                $res_grain = mysqli_query($conn, $sql_grain);
                if (mysqli_num_rows($res_grain) > 0) {
                    while ($row_grain = mysqli_fetch_assoc($res_grain)) {
                        echo "<div class='types_content_items'>
                                <a href='userfiles/u_show_goods.php?g_id=" . $row_grain['g_id'] . "'>
                                <div class='items_img'>
                                    <img src='goods_imgs/" . $row_grain['g_img'] . "'>
                                </div>
                                <div class='items_text'>
                                    <span class='items_text_name'>" . $row_grain['g_name'] . "</span>
                                    <span class='items_text_price'>￥" . $row_grain['g_price'] . "</span>
                                </div>
                            </a></div>";
                    }
                } else {
                    echo "
                    <div class='types_content_items'>
                        <div class='none_info_items'>
                            该分类暂无商品
                        </div>
                    </div>";
                }
                ?>
            </div>
        </div>

        <div class="container">
            <div class="types_title">
                <span class="types_title_img">
                    <img src="img/粮油.svg">
                </span>
                <span class="types_title_text">放心粮油</span>
                <span class="types_title_more"><a href="">更多></a></span>
            </div>
            <div class="types_content">
                <?php
                //查询粮油类别售卖数量前4商品
                $sql_grain = "SELECT * FROM tb_goods_info WHERE g_type = '粮油' AND g_is_sell = 1 ORDER BY g_sell_num DESC LIMIT 4";
                $res_grain = mysqli_query($conn, $sql_grain);
                if (mysqli_num_rows($res_grain) > 0) {
                    while ($row_grain = mysqli_fetch_assoc($res_grain)) {
                        echo "<div class='types_content_items'>
                                <a href='userfiles/u_show_goods.php?g_id=" . $row_grain['g_id'] . "'>
                                <div class='items_img'>
                                    <img src='goods_imgs/" . $row_grain['g_img'] . "'>
                                </div>
                                <div class='items_text'>
                                    <span class='items_text_name'>" . $row_grain['g_name'] . "</span>
                                    <span class='items_text_price'>￥" . $row_grain['g_price'] . "</span>
                                </div></a>
                            </div>";
                    }
                } else {
                    echo "
                    <div class='types_content_items'>
                        <div class='none_info_items'>
                            该分类暂无商品
                        </div>
                    </div>";
                }
                ?>
            </div>
        </div>

        <div class="container">
            <div class="types_title">
                <span class="types_title_img">
                    <img src="img/水果.svg">
                </span>
                <span class="types_title_text">新鲜水果</span>
                <span class="types_title_more"><a href="">更多></a></span>
            </div>
            <div class="types_content">
                <?php
                //查询水果类别售卖数量前4商品
                $sql_fruit = "SELECT * FROM tb_goods_info WHERE g_type = '水果' AND g_is_sell = 1 ORDER BY g_sell_num DESC LIMIT 4";
                $res_fruit = mysqli_query($conn, $sql_fruit);
                if (mysqli_num_rows($res_fruit) > 0) {
                    while ($row_fruit = mysqli_fetch_assoc($res_fruit)) {
                        echo "<div class='types_content_items'>
                                <a href='userfiles/u_show_goods.php?g_id=" . $row_fruit['g_id'] . "'>
                                <div class='items_img'>
                                    <img src='goods_imgs/" . $row_fruit['g_img'] . "'>
                                </div>
                                <div class='items_text'>
                                    <span class='items_text_name'>" . $row_fruit['g_name'] . "</span>
                                    <span class='items_text_price'>￥" . $row_fruit['g_price'] . "</span>
                                </div></a>
                            </div>";
                    }
                } else {
                    echo "
                    <div class='types_content_items'>
                        <div class='none_info_items'>
                            该分类暂无商品
                        </div>
                    </div>";
                }
                ?>
            </div>
        </div>

        <div class="container">
            <div class="types_title">
                <span class="types_title_img">
                    <img src="img/海鲜.svg">
                </span>
                <span class="types_title_text">生态海鲜</span>
                <span class="types_title_more"><a href="">更多></a></span>
            </div>
            <div class="types_content">
                <?php
                //查询生鲜类别售卖数量前4商品
                $sql_seafood = "SELECT * FROM tb_goods_info WHERE g_type = '生鲜' AND g_is_sell = 1 ORDER BY g_sell_num DESC LIMIT 4";
                $res_seafood = mysqli_query($conn, $sql_seafood);
                if (mysqli_num_rows($res_seafood) > 0) {
                    while ($row_seafood = mysqli_fetch_assoc($res_seafood)) {
                        echo "<div class='types_content_items'>
                                <a href='userfiles/u_show_goods.php?g_id=" . $row_seafood['g_id'] . "'>
                                <div class='items_img'>
                                    <img src='goods_imgs/" . $row_seafood['g_img'] . "'>
                                </div>
                                <div class='items_text'>
                                    <span class='items_text_name'>" . $row_seafood['g_name'] . "</span>
                                    <span class='items_text_price'>￥" . $row_seafood['g_price'] . "</span>
                                </div></a>
                            </div>";
                    }
                } else {
                    echo "
                    <div class='types_content_items'>
                        <div class='none_info_items'>
                            该分类暂无商品
                        </div>
                    </div>";
                }
                ?>
            </div>
        </div>
    </main>
    <footer class="fixed-bottom">
        古韵超市网上购物系统© 2025® All Rights Reserved.
    </footer>
</body>

</html>